package com.dubito.noteapp.domain.usecase

import com.dubito.noteapp.data.database.repository.NoteRepository
import com.dubito.noteapp.domain.model.InvalidNoteException
import com.dubito.noteapp.domain.model.Note

/**
 * author: LiLiang
 * createTime: 2022/10/7-11:54
 * remark:
 **/
class AddNote(private val repository: NoteRepository) {

    suspend operator fun invoke(note: Note) {
        if (note.title.isBlank()) {
            throw InvalidNoteException("标题不能为空")
        }
        if (note.content.isBlank()) {
            throw InvalidNoteException("内容不能为空")
        }
        repository.insertNote(note)
    }
}